﻿using System.Collections.Generic;
using Notoric.Commanding.CommandBase;

namespace Notoric.Commanding
{
    /// <summary>
    /// Implements a simple macro command that executes the commands from the <see cref="Commands"/> list
    /// in the order given by the list.<br/>
    /// The commands can be only <see cref="SingleUseCommandBase"/> instances and the macro command cannot be undone.
    /// </summary>
    /// <seealso cref="UndoableMacroCommand"/>
    /// <seealso cref="SingleUseCommandBase"/>
    public class SingleUseMacroCommand : SingleUseCommandBase
    {
        #region Inherited SingleUseCommandBase Abstract Members

        /// <summary>
        /// Executes all the commands in the <see cref="Commands"/> list.
        /// </summary>
        /// <param name="parameter">
        /// Data used by the command. If the command does not require data to be passed, this object can be set to <see langword="null"/>.
        /// The parameter value is passed to all the executed subcommands.
        /// </param>
        protected override void CommandOperation(object parameter)
        {
            foreach (SingleUseCommandBase cmd in commands)
            {
                cmd.Execute(parameter);
            }
        }

        #endregion

        #region Public Properties

        /// <summary>
        /// Gets the list of the commands that are executed in this macro.
        /// </summary>
        /// <value>
        /// <para>
        /// Type: <see cref="SingleUseCommandBase"/>
        /// </para>
        /// <para>
        /// Collection of the commands that are part of this macro. The commands are executed in the same
        /// order as they are in the list.
        /// </para>
        /// </value>
        public List<SingleUseCommandBase> Commands
        {
            get { return commands; }
        }

        #endregion

        #region Private Fields

        /// <summary>
        /// Holds the list of the commands that are part of this macro.
        /// </summary>
        private List<SingleUseCommandBase> commands = new List<SingleUseCommandBase>();

        #endregion
    }
}
